<?php
defined('SYSPATH') OR die('No direct access allowed.');
/**
 * aktivasi.php
 * @author ranuandra
 *
 * 11 Mei 2012 08:41:48
 *
 * 
 */


class Controller_Aktivasi extends Kohana_Nasmoco
{
	
	
	public function action_index()
	{
		$db = Database::instance();
		$db->begin();
		$pin = Request::current()->param('pin');
		$email = Request::current()->param('email');
		$view = View::factory('home/aktivasi');
		try 
		{
			$member = ORM::factory('user')->where('email', '=', $_GET['email'])->where('pin', '=', $_GET['pin'])->find();
			if(isset($member->id))
			{
				$aktivasi = ORM::factory('user')->where('id', '=', $member->id)->find();
				$aktivasi->activated = 1;
				$aktivasi->update();
				$db->commit();
				$view->message = "Aktivasi berhasil";
			}
			else 
			{
				$view->message = "Aktivasi gagal";
			}
		}
		catch (ORM_Validation_Exception $e) 
		{
			$db->rollback();
		}
		
		$this->template->container = $view;
	}
}